<extend name="_layout/main"/>
<block name="head">
    <style>
        #method {
            margin: 0;
            padding: 0;
            width: 100%;
        }
    </style>
</block>
<block name="top">
    <header class="mui-bar mui-bar1 mui-bar-nav mui-bar-nav1" id="header">
        <a class="btn" href="{:U('Member/index')}">
            <i class="iconfont icon-fanhui"></i>
        </a>
        <div class="top-sch-box top-sch-boxtwo top-sch-boxthree flex-col">
            返回
        </div>
    </header>
</block>
<block name="content">
    <div class="warp warpthree clearfloat">
        <div class="h-top h-topone clearfloat box-s">
            <span>我的现金</span>
            <p>{$wealth.balance}</p>
        </div>

        <div class="recharge clearfloat">
            <div class="czhi clearfloat box-s">
                <p>充值金额</p>
                <input type="text" id="amount" name="amount" value="" placeholder="请输入金额"/>
                <span>元</span>
            </div>
            <div class="czhi clearfloat box-s" id='showUserPicker'>

                <select name="method" id="method">
                    <option value="">支付方式</option>
                    <volist name="payments" id="pay">
                        <option value="{$pay.id}">{$pay.name}</option>
                    </volist>
                </select>
            </div>
            <!--<a href="#" class="center-btn center-btntwo db ra3">点击上传文件</a>-->
            <div class="guize clearfloat box-s ra3">
                <h3>充值说明</h3>
                <div class="content clearfloat">
                    {$setting.recharge_annouce|stripslashes|htmlspecialchars_decode}
                </div>
            </div>
            <div class="bottom clearfloat">
                <a href="{:U('Pay/create_order')}" id="btn-save" class="db fl btn ra3">确定</a>
                <a href="javascript:history.go(-1)" class="db fr btn ra3">取消</a>
            </div>
        </div>

    </div>
</block>
<block name="scripts">
    <script>
        var min_amount = "{$setting.min_recharge_amount|default=100}";
        $(document).on('click', '#btn-save', function (e) {
            e.preventDefault();
            var url=$(this).attr('href');
            var amount = $("#amount").val();
            var method = $("#method").val();
            if(!url || url == ''){
                return;
            }
            if (!amount || isNaN(amount)) {
                mui.alert('请输入合适的金额');
                return;
            }
            if (parseFloat(min_amount) > amount) {
                mui.alert('充值金额最少' + min_amount);
                return;
            }
            if (!method || isNaN(method)) {
                mui.alert('请选择支付方式');
                return;
            }
            $.post(url, {method: method, amount: amount}, function (xdata) {
                if(xdata.status == 'success'){
                    document.location.href = xdata.data.url;
                }else{
                    mui.alert(xdata.message);
                }
            }, 'json')
        })
    </script>
</block>